package cn.hnbjx.prepaid.controller;

import cn.hnbjx.prepaid.service.UploadService;
import cn.hnbjx.prepaid.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;

    //上传图片
    @PostMapping("/admin/upload/uploadImg")
    public Result uploadImg(MultipartFile file, HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        return Result.ok(uploadService.uploadImg(file));
    }
    @PostMapping("/api/upload/uploadImg")
    public Result uploadImg1(MultipartFile file, HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        return Result.ok(uploadService.uploadImg(file));
    }
}
